import time

import win32api,win32con,win32gui
import numpy as np
from PIL import ImageGrab
import cv2
import funlib
import time
import hashvs

def int_photo():
    BOX = (1630, 980, 1900, 1040)
    # 左上角坐标和右下角坐标
    # 调整box的值即可改变截取区域

    screen = np.array(ImageGrab.grab(bbox=BOX))
    #cv2.imshow("window", cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
    cv2.imwrite("wechat0.jpg", screen)



def get_photo():
    BOX = (1630, 980, 1900, 1040)
    # 左上角坐标和右下角坐标
    # 调整box的值即可改变截取区域

    screen = np.array(ImageGrab.grab(bbox=BOX))
    #cv2.imshow("window", cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
    return screen


def get_size():
    x = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)   #获得屏幕分辨率X轴
    y = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)   #获得屏幕分辨率Y轴
    #print(x, y)
    return (x,y)


#print(funlib.move(1920,1080))

def mouse():
    funlib.move(1920-40, 1080-75) # x,y
    #funlib.left_down()
def click():
    funlib.left_click()


#当两图对比度达到某值，判定为微信通话呼叫，执行鼠标点击接听。
def startchech():
    img1 = get_photo()
    img2 = 'wechat0.jpg'
    print(type(img1),type(img2))
    value = hashvs.check(img1,img2)
    print(value)
    if value < 10:
        mouse()
        click()

def run():
    while True:
        startchech()
        time.sleep(20)

run()
